import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import VueDevTools from 'vite-plugin-vue-devtools'
import { VitePWA  } from 'vite-plugin-pwa'
import VueRouter from 'unplugin-vue-router/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import { resolve } from 'node:path'

// https://vite.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "~": resolve("./src")
    }
  },
  plugins: [
    VueRouter({
      dts: 'src/types/typed-router.d.ts',
      importMode: 'async',
      exclude: ['**/components/**/*.vue']
    }),
    Vue(),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        'pinia',
        '@vueuse/core',
        VueRouterAutoImports
      ],
      dts: 'src/types/auto-import.d.ts',
      dirs: [
        './src/composables',
        './store',
        './utils',
      ],
      resolvers: [
        ElementPlusResolver(),
        // IconsResolver({
        //   prefix: 'icon',
        //   enabledCollections: ['ep', 'mdi', 'f7'] 
        // }),
      ],
    }),
    Components({
      dirs: [
        'src/components',
      ],
      dts: 'src/types/components.d.ts',
      directoryAsNamespace: true,
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          prefix: 'icon', // 自动引入的Icon组件统一前缀，默认为 i，设置false为不需要前缀
          // {prefix}-{collection}-{icon} 使用组件解析器时，您必须遵循名称转换才能正确推断图标。
          // alias: { park: 'icon-park' } 集合的别名
          enabledCollections: ['ep', 'mdi', 'f7'] // 这是可选的，默认启用 Iconify 支持的所有集合['mdi']
        })
      ],
    }),
    Icons({
      autoInstall: true,
      compiler: "vue3",
    }),
    VitePWA({
      workbox: {
        maximumFileSizeToCacheInBytes: 10000000
      }
    }),
    VueDevTools(),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler'
      },
    }
  }
})
